package com.guli.file.controller;

import com.guli.common.response.Result;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
@RequestMapping("file/upload")
public class NativeUploadController {


    //文件上传本地
    @PostMapping("/native")
    public Result nativeUpload(@RequestParam("file")MultipartFile file){
        //原始文件名
        String originalFilename = file.getOriginalFilename();
        //上传到本地
        File file1 = new File("C:\\Users\\Y\\Desktop\\bizhi\\nativefile", originalFilename);
        //执行上传
        try {
            file.transferTo(file1);
        } catch (IOException e) {
            e.printStackTrace();
        }
        String imageURl="http://localhost:18180/images/"+originalFilename;
        return new Result(true, "100", imageURl);
    }
}
